{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "23657e1e-a40c-43c0-a6bc-0b3a86a8a3d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pytz"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad98b87a-c6dd-45b6-a972-bde27f8cbf4d",
   "metadata": {},
   "source": [
    "# 字符串操作\n",
    "\n",
    "numpy.char 模块为类型 numpy.string_ 或的数组提供了一组向量化的字符串操作numpy.unicode_。\n",
    "它们全部基于Python标准库中的字符串方法。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e03922b-1eda-436c-9658-9e65662b513b",
   "metadata": {
    "toc-hr-collapsed": true
   },
   "source": [
    "## 字符串操作\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "add(x1, x2)|返回两个str或unicode数组的按元素的字符串连接。\n",
    "multiply(a, i)|返回（a * i），即按元素方式的字符串多重连接。\n",
    "mod(a, values)|返回（a％i），这是Python 2.6之前的字符串格式（迭代），针对一对str或unicode的array_likes元素。\n",
    "capitalize(a)|返回的拷贝一个只有资本的每个元素的第一个字符。\n",
    "center(a, width[, fillchar])|返回的拷贝一与在长度的字符串居中其元素宽度。\n",
    "decode(a[, encoding, errors])|按元素调用str.decode。\n",
    "encode(a[, encoding, errors])|逐元素调用str.encode。\n",
    "expandtabs(a[, tabsize])|返回每个字符串元素的副本，其中所有制表符都被一个或多个空格替换。\n",
    "join(sep, seq)|返回一个字符串，该字符串是序列seq中字符串的串联。\n",
    "ljust(a, width[, fillchar])|返回与元素的数组一个左对齐的长度的字符串宽度。\n",
    "lower(a)|返回一个将元素转换为小写的数组。\n",
    "lstrip(a[, chars])|对于每一个元素一个，去除了主角返回副本。\n",
    "partition(a)|将每个元素划分为大约sep。\n",
    "replacee(a, old, new[, count])|对于每一个元素一个，返回字符串的副本串中出现的所有旧的换成新的。\n",
    "rjust(a, width[, fillchar])|返回与元素的数组一个右对齐的长度的字符串宽度。\n",
    "rpartition(a, sep)|在最右边的分隔符周围分割（分割）每个元素。\n",
    "rsplit(a[, sep, maxsplit])|在每个元件一个，返回的词的列表字符串中，使用月作为分隔符串。\n",
    "rstrip(a[, chars])|在每个元件一个，返回与除去尾部字符的副本。\n",
    "split(a[, sep, maxsplit])|在每个元件一个，返回的词的列表字符串中，使用月作为分隔符串。\n",
    "splitlines(a[, keepends])|在每个元件一个，返回行的列表中的元素，在断裂线边界。\n",
    "strip(a[, chars])|在每个元件一个，其中移除了前缘和后字符返回副本。\n",
    "swapcase(a)|按元素返回字符串的副本，该字符串的大写字符转换为小写，反之亦然。\n",
    "title(a)|返回字符串或unicode的逐元素标题区分大小写的版本。\n",
    "translate(a, table[, deletechars])|对于每一个元素一个，返回其中可选的参数中出现的所有字符的字符串拷贝deletechars被删除，而剩余的字符已经通过给定的转换表映射。\n",
    "upper(a)|返回一个数组，其中元素转换为大写。\n",
    "zfill(a, width)|返回用零填充的数字字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6eeb6625-06ab-440a-a3ce-a9bb43ff6b0f",
   "metadata": {},
   "source": [
    "### char.add(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6ee5ed4b-6746-4608-8fd1-8c594f653979",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array('abcdef', dtype='<U6')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array(\"abc\")\n",
    "b = np.array(\"def\")\n",
    "np.char.add(a,b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2135eabe-d424-49cd-8d2b-fc81e792be82",
   "metadata": {},
   "source": [
    "### char.multiply(a, i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e5b47f8b-9110-4f03-8458-b81d62f01ec5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aaa', 'bbb', 'ccc'], dtype='<U3')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"a\", \"b\", \"c\"])\n",
    "np.char.multiply(a, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f5695c0e-ef45-40ce-a314-77df42bf3701",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a', 'bb', 'ccc'], dtype='<U3')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i = np.array([1, 2, 3])\n",
    "np.char.multiply(a, i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a7ccfbc5-2857-4919-858e-f3ca991a0ee9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a', 'aa', 'aaa'], dtype='<U3')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.multiply(np.array(['a']), i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a018cf89-07f3-4675-9103-efef4e36b2f5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['aaa', 'bbb', 'ccc'],\n",
       "       ['ddd', 'eee', 'fff']], dtype='<U3')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))\n",
    "np.char.multiply(a, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8bd5f606-2ca8-43a5-ab62-5327f21c432f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['a', 'bb', 'ccc'],\n",
       "       ['d', 'ee', 'fff']], dtype='<U3')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.multiply(a, i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62517a10-77d9-4659-987b-fc2af02091fc",
   "metadata": {},
   "source": [
    "### char.mod(a, values)\n",
    "\n",
    "Return (a % i), that is pre-Python 2.6 string formatting (interpolation), element-wise for a pair of array_likes of str or unicode."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fdf4419-9d4b-4942-b782-61230bb7c392",
   "metadata": {},
   "source": [
    "### char.capitalize(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b07757c7-2a96-43f4-8d02-1f45038dcb62",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'a1b2', b'1b2a', b'b2a1', b'2a1b'], dtype='|S4')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ded06462-a171-4a81-b542-22479ac3cc61",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'A1b2', b'1b2a', b'B2a1', b'2a1b'], dtype='|S4')"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.capitalize(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "afdc08a1-5262-49fb-8260-8075760e6971",
   "metadata": {},
   "source": [
    "### char.center(a, width, fillchar=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "41612045-11a6-40e2-85e6-5a42d71dc872",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['a1b2','1b2a','b2a1','2a1b']); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2ee6d33e-3397-45d9-b967-c7795bbd3893",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['   a1b2  ', '   1b2a  ', '   b2a1  ', '   2a1b  '], dtype='<U9')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.center(c, width=9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ebd21861-e440-4f72-b439-8825e8048720",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='<U9')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.center(c, width=9, fillchar='*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6d67bc4c-8ab0-411c-af40-881c3a6dbfc8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a', '1', 'b', '2'], dtype='<U1')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.center(c, width=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5cc523d-fc3e-4bf4-9239-ced8f76d5df0",
   "metadata": {},
   "source": [
    "### char.decode(a, encoding=None, errors=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "90c48632-e650-49e9-bef6-902837ee0eed",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'\\x81\\xc1\\x81\\xc1\\x81\\xc1', b'@@\\x81\\xc1@@',\n",
       "       b'\\x81\\x82\\xc2\\xc1\\xc2\\x82\\x81'], dtype='|S7')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array([b'\\x81\\xc1\\x81\\xc1\\x81\\xc1', b'@@\\x81\\xc1@@',\n",
    "              b'\\x81\\x82\\xc2\\xc1\\xc2\\x82\\x81'])\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c27f7b51-78b5-4566-962b-eb33a3683964",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.decode(c, encoding='cp037')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cba53a09-316f-4db9-a99c-d548eabf6751",
   "metadata": {},
   "source": [
    "### char.encode(a, encoding=None, errors=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "e507d6e8-a37b-4d3a-9f7c-46b8199e15e0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'aAaAaA', b'  aA  ', b'abBABba'], dtype='|S7')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.encode(['aAaAaA', '  aA  ', 'abBABba'], encoding='utf-8')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d050a81a-ddd6-41a5-b16a-22059f989e95",
   "metadata": {},
   "source": [
    "### char.expandtabs(a, tabsize=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0a24a9fc-c021-433b-929e-2a4e8e577476",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.expandtabs(['aAaAaA', '  aA  ', 'abBABba'], tabsize=8)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68978ecf-f633-4484-a5a5-6787aa7e9b85",
   "metadata": {},
   "source": [
    "### char.join(sep, seq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2e55b77f-5424-475b-9c9c-d69bcb00e1a1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array('o-s-d', dtype='<U5')"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.join('-', 'osd')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "29090d78-3ee4-423e-bfdb-1cd2f8cd2b17",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['g-h-c', 'o.s.d'], dtype='<U5')"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.join(['-', '.'], ['ghc', 'osd'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fd19502-f341-4af2-85a0-daa21f6ccb99",
   "metadata": {},
   "source": [
    "### char.ljust(a, width, fillchar=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1707a791-3854-4d49-819d-2d7f71956556",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a0000', 'b0000'], dtype='<U5')"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.ljust([\"a\", \"b\"], 5, fillchar=\"0\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4756be84-061a-4c93-87a9-4f402118f8a4",
   "metadata": {},
   "source": [
    "### char.lower(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c2aa56b4-b4cd-4921-87c1-cfdeb1220a0b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['A1B C', '1BCA', 'BCA1']); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "4f3e52ea-9472-482e-90a1-f9df4d6784d3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a1b c', '1bca', 'bca1'], dtype='<U5')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.lower(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7756cb5-e001-467c-abdc-6e10924170dd",
   "metadata": {},
   "source": [
    "### char.lstrip(a, chars=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b3c989a1-51b8-4432-ba3a-ccd36e91b32d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['aAaAaA', '  aA  ', 'abBABba'])\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ee93f9c9-8e63-432e-bfac-2aac7eace0ac",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['AaAaA', '  aA  ', 'bBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.lstrip(c, 'a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4454f679-98dd-4da4-a4da-976a262214f7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.lstrip(c, 'A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c6b99e94-100e-4194-9653-9ead27d7f940",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(np.char.lstrip(c, ' ') == np.char.lstrip(c, '')).all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b1fed496-9854-4390-8638-75aea0d65368",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(np.char.lstrip(c, ' ') == np.char.lstrip(c, None)).all()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5120243e-29a7-4403-97cb-1d56f66fc404",
   "metadata": {},
   "source": [
    "### char.partition(a, sep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "2ce47440-6335-49e8-8e8d-59bf3974e11c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a', ',', 'b'], dtype='<U1')"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.partition(\"a,b\",\",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "052d64c1-6d96-4cb6-9385-2d043be59fb7",
   "metadata": {},
   "source": [
    "### char.replace(a, old, new, count=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b10b261b-eda1-4f63-a31b-a8b0680d4bf5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['That is a banana', 'Monkeys eat bananas'], dtype='<U19')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"That is a mango\", \"Monkeys eat mangos\"])\n",
    "np.char.replace(a, 'mango', 'banana')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "a1b30199-2c24-4fb8-907e-7a80e97897d0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"The dish is fresh\", \"This is it\"])\n",
    "np.char.replace(a, 'is', 'was')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f0c2f4b-e8fb-42bf-9ea7-30cc53640f72",
   "metadata": {},
   "source": [
    "### char.rjust(a, width, fillchar=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "6ee63ead-9338-4578-b5f6-534016f52f1f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['0000a', '0000b'], dtype='<U5')"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rjust([\"a\",\"b\"],5,fillchar=\"0\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c9d07270-bcb0-4d36-b6fb-3cb6a5723046",
   "metadata": {},
   "source": [
    "### char.rpartition(a, sep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "cc526654-0797-4be1-bba2-ab31f12f129f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a', ',', 'b'], dtype='<U1')"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rpartition(\"a,b\",\",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d221a01-dcbb-4bfd-84ac-0fe769e4fdac",
   "metadata": {},
   "source": [
    "### char.rsplit(a, sep=None, maxsplit=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "98a1b9c9-e28e-48b6-831b-e9bdc3e510b9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(list(['a,b', 'c', 'd']), dtype=object)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rsplit(\"a,b,c,d\",sep=\",\",maxsplit=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d796a57-44bf-42ef-8ad7-5e0a1120a1ea",
   "metadata": {},
   "source": [
    "### char.rstrip(a, chars=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d3ffb5a8-d0f9-4470-8fca-24bf1d36c243",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'aAaAaA', b'abBABba'], dtype='|S7')"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['aAaAaA', 'abBABba'], dtype='S7'); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "e41ab9e1-58a1-41ca-9c30-2902953f2769",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'aAaAaA', b'abBABb'], dtype='|S7')"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rstrip(c, b'a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9d977494-99e0-4783-ae7d-59e278269944",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'aAaAa', b'abBABba'], dtype='|S7')"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rstrip(c, b'A')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cf27e58-79d8-4667-8b11-2a63e1b1ede9",
   "metadata": {},
   "source": [
    "### char.split(a, sep=None, maxsplit=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "eebc9222-7bab-4eb3-9301-0abd13c3a32f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(list(['a', 'b', 'c,d']), dtype=object)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.split(\"a,b,c,d\",sep=\",\",maxsplit=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "429c998d-2a25-4896-a432-7a15065e071e",
   "metadata": {},
   "source": [
    "### char.splitlines(a, keepends=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "9961dc19-53ed-4b3d-a3c1-41e64d19946c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([list(['a']), list(['b'])], dtype=object)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.splitlines([\"a\",\"b\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9112de37-ee3f-4b02-b588-1e9d2331c7b8",
   "metadata": {},
   "source": [
    "### char.strip(a, chars=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0391ab1a-e44a-4cb7-8d6e-1808648db81c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['aAaAaA', '  aA  ', 'abBABba'])\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "850a71a6-5984-47f3-8ce3-7acb4c02a69e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.strip(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e77646d2-0ff2-4668-a0ee-971a5052f2f9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['AaAaA', '  aA  ', 'bBABb'], dtype='<U7')"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.strip(c, 'a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "15ecd702-42a6-471a-8e4a-b26990699ec8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAa', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.strip(c, 'A')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9ff4c64-5f17-40e7-959a-d62cf533f9f0",
   "metadata": {},
   "source": [
    "### char.swapcase(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "5ec1fe68-0adf-4f82-a30a-e3ac8c663189",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'a1B c', b'1b Ca', b'b Ca1', b'cA1b'], dtype='|S5')"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "f9917081-b119-42f6-881f-75fde088768c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'A1b C', b'1B cA', b'B cA1', b'Ca1B'], dtype='|S5')"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.swapcase(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be6408c3-ed13-495f-ac3f-390f3e5e3c04",
   "metadata": {},
   "source": [
    "### char.title(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "9666418e-d5af-4687-8edd-a1cd640f1dc5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'a1b c', b'1b ca', b'b ca1', b'ca1b'], dtype='|S5')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "06817b29-652c-4d2c-a614-a3a0de5d3ee8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([b'A1B C', b'1B Ca', b'B Ca1', b'Ca1B'], dtype='|S5')"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.title(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3b84927-14ec-4e7f-90f2-f1cea0039640",
   "metadata": {},
   "source": [
    "### char.translate(a, table, deletechars=None)\n",
    "\n",
    "For each element in a, return a copy of the string where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c7cc0a8-7bdc-4aad-b347-e697daa22333",
   "metadata": {},
   "source": [
    "### char.upper(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "5178cb2d-dd62-4c22-b609-c9cb0afb3b75",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['a1b c', '1bca', 'bca1'], dtype='<U5')"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['a1b c', '1bca', 'bca1']); c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "c3f786ce-7c97-4626-a014-895434ceefaf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.upper(c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b32dbbc3-905b-4478-a71c-4df300be2c4f",
   "metadata": {},
   "source": [
    "### char.zfill(a, width)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "f3887941-5c39-4803-b787-aac14eaadcac",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array('00abc', dtype='<U5')"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.zfill(\"abc\",5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9840f3a4-ff54-4714-bf3c-4f30dda5470f",
   "metadata": {
    "toc-hr-collapsed": true
   },
   "source": [
    "## 比较\n",
    "\n",
    "与标准numpy比较运算符不同，char 模块中的运算符在执行比较之前会删除结尾的空白字符。\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "equal(x1, x2)|按元素返回（x1 == x2）。\n",
    "not_equal(x1, x2)|按元素返回（x1！= x2）。\n",
    "greater_equal(x1, x2)|按元素返回（x1> = x2）。\n",
    "less_equal(x1, x2)|按元素返回（x1 <= x2）。\n",
    "greater(x1, x2)|按元素返回（x1> x2）。\n",
    "less(x1, x2)|按元素返回（x1 < x2）。\n",
    "compare_chararrays(a, b, cmp_op, rstrip)|使用cmp_op指定的比较运算符对两个字符串数组执行逐元素比较。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1544522-08eb-4ec7-a2f7-36c8a52f8f02",
   "metadata": {},
   "source": [
    "### char.equal(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "56b00d2e-53ac-44d7-946a-50bffc8110a7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.equal(\"22\",\"22\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80c49632-08ff-4d5a-8574-5cc781f3ff50",
   "metadata": {},
   "source": [
    "### char.not_equal(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "ddf7cede-2dda-4d9d-a45f-b8649839db96",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(False)"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.not_equal(\"22\", \"22\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e847dc5-35bc-4d96-a60e-b2d5aa0d903b",
   "metadata": {},
   "source": [
    "### char.greater_equal(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "1dccca06-cd7d-4ca0-8b50-c11d50f14cb8",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.greater_equal(\"25\", \"012\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fadc8d3-b719-4b14-b679-43ac35bc2fbd",
   "metadata": {},
   "source": [
    "### char.less_equal(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "2e4924b4-7e7d-4eb7-8260-7de29973c529",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.less_equal(\"12\", \"22\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2e31369-c068-464b-bfe1-4e7d311c2e3d",
   "metadata": {},
   "source": [
    "### char.greater(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "5eda0908-e456-49a8-8de7-9e5ab446c175",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.greater(\"25\",\"22\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6fef982-b49a-4b11-91f2-ed93c5c78561",
   "metadata": {},
   "source": [
    "### char.less(x1, x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "c1039c48-924f-4f16-96cd-6607c45f2798",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.less(\"12\",\"22\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "221aa8fe-a39a-4d78-acc4-757c8815360b",
   "metadata": {},
   "source": [
    "### char.compare_chararrays(a1, a2, cmp, rstrip)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "c288d6f2-8b5b-4aa3-97d4-0812812f70cf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False,  True, False])"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"a\", \"b\", \"cde\"])\n",
    "b = np.array([\"a\", \"a\", \"dec\"])\n",
    "np.char.compare_chararrays(a, b, \">\", True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d70e659-6b17-4b2f-9adf-00100b773163",
   "metadata": {
    "toc-hr-collapsed": true
   },
   "source": [
    "## 字符串信息\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "count(a, sub[, start, end])|返回一个数组，该数组的子字符串sub的不重叠出现次数在[ start，end ] 范围内。\n",
    "endswith(a, suffix[, start, end])|返回一个布尔值阵列，其是真正的，其中在字符串元素一个结尾的后缀，否则假。\n",
    "find(a, sub[, start, end])|对于每个元素，返回找到子字符串sub的字符串中的最低索引。\n",
    "index(a, sub[, start, end])|与相似find，但是在未找到子字符串时引发ValueError。\n",
    "isalpha(a)|如果字符串中的所有字符都是字母并且至少包含一个字符，则对每个元素返回true，否则返回false。\n",
    "isalnum(a)|如果字符串中的所有字符都是字母数字并且至少包含一个字符，则对每个元素返回true，否则返回false。\n",
    "isdecimal(a)|对于每个元素，如果元素中只有十进制字符，则返回True。\n",
    "isdigit(a)|如果字符串中的所有字符都是数字并且至少有一个字符，则对每个元素返回true，否则返回false。\n",
    "islower(a)|如果字符串中所有大小写的字符均为小写且至少有一个大小写的字符，则对每个元素返回true，否则返回false。\n",
    "isnumeric(a)|对于每个元素，如果元素中仅包含数字字符，则返回True。\n",
    "isspace(a)|如果字符串中只有空格字符且至少有一个字符，则对每个元素返回true，否则返回false。\n",
    "istitle(a)|如果该元素是一个带标题的字符串并且至少包含一个字符，则为每个元素返回true，否则返回false。\n",
    "isupper(a)|如果字符串中所有大小写的字符均为大写且至少有一个字符，则为每个元素返回true，否则返回false。\n",
    "rfind(a, sub[, start, end])|在每个元件一个，在字符串中返回指数最高，其中子子被发现，使得子包含[内开始，结束。\n",
    "rindex(a, sub[, start, end])|与相似rfind，但是在未找到子字符串sub时引发ValueError。\n",
    "startswith（一个，前缀[，开始，结束]）|返回一个布尔数组是真正的地方在字符串元素一个开头前缀，否则假。\n",
    "str_len(a)|按元素返回len（a）。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "083e58cf-0f22-4bbc-be05-0b399fbade57",
   "metadata": {
    "tags": []
   },
   "source": [
    "### char.count(a, sub, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "4e61db21-19b2-4999-973c-fcc5ec2e2772",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = np.array(['aAaAaA', '  aA  ', 'abBABba'])\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "81418d09-8296-486a-ad01-bab114010bbe",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 1, 1])"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.count(c, 'A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "0560d563-38f5-4ddc-8111-94f371102d7a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 1, 0])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.count(c, 'aA')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "4b6eb4c4-1503-4b73-b732-d7be4bff5ead",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 1, 1])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.count(c, 'A', start=1, end=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "b3a5b696-7157-4da9-ad88-099ef40c9848",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0])"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.count(c, 'A', start=1, end=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e87ff160-e253-4115-be5e-91d5879b8536",
   "metadata": {},
   "source": [
    "### char.endswith(a, suffix, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "7dd1f9f1-3c83-48e5-94b6-3cbf49230eb0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['foo', 'bar'], dtype='<U3')"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = np.array(['foo', 'bar'])\n",
    "s[0] = 'foo'\n",
    "s[1] = 'bar'\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "785868e3-2b48-4605-b3e4-524919521267",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False,  True])"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.endswith(s, 'ar')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "859fad03-dada-4ef7-9bbc-f47675792249",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False,  True])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.endswith(s, 'a', start=1, end=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aca7f0c5-b3f7-42cc-ba98-720b74a12f87",
   "metadata": {},
   "source": [
    "### char.find(a, sub, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "cce1bdc8-18b4-4155-ae7f-2690d2d1f722",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"NumPy is a Python library\"])\n",
    "np.char.find(a, \"Python\", start=0, end=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23e793ff-c724-4e67-bdf2-0cad9e3c5da5",
   "metadata": {},
   "source": [
    "### char.index(a, sub, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "2c742175-e245-4339-900a-63ba7403a9c5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([9])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"Computer Science\"])\n",
    "np.char.index(a, \"Science\", start=0, end=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "806ead0a-ff4d-4d6d-8167-a995612400f4",
   "metadata": {},
   "source": [
    "### char.isalpha(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "4675eb97-7319-4a30-a7a0-eee1abcd0a48",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.isalpha(\"ab\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a9b8eb7-2b4c-482d-aeeb-965d08f1f68d",
   "metadata": {},
   "source": [
    "### char.isalnum(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "a2c74581-352f-42ae-89c9-176472e227ce",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.isalnum(\"12\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12153169-c91c-49be-9648-0a6a6d5e5720",
   "metadata": {},
   "source": [
    "### char.isdecimal(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "752a62f5-43e8-4e92-83c4-89e29326f037",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True, False, False, False])"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.isdecimal(['12345', '4.99', '123ABC', ''])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f3cb0a8-668d-4303-a8e2-b59c1bf7eee0",
   "metadata": {},
   "source": [
    "### char.isdigit(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "cbe00412-d89d-4c4c-81f1-80109b1ceab2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False,  True])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array(['a', 'b', '0'])\n",
    "np.char.isdigit(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "99c0927f-2ac7-4602-8833-d601983207f2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False,  True],\n",
       "       [False,  True,  True]])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([['a', 'b', '0'], ['c', '1', '2']])\n",
    "np.char.isdigit(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c0b17c3-4ee3-4fe1-9281-a060eb25fd9e",
   "metadata": {},
   "source": [
    "### char.islower(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "48f71fa3-326b-4850-a30e-3fedccf25474",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.islower(\"abc1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "829d7ab7-2acf-4b51-afbb-c26c359cc9e1",
   "metadata": {},
   "source": [
    "### char.isnumeric(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "5cc6de30-5df9-4018-9cdc-1790b03d7268",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True, False, False, False, False])"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.isnumeric(['123', '123abc', '9.0', '1/4', 'VIII'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dade3ea8-4361-4aac-9fc0-e822d1c5be38",
   "metadata": {},
   "source": [
    "### char.isspace(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "ca4d6147-ec37-4bf7-b6bf-89955de49c7b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.isspace(\" \")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69366e33-ea5e-4264-9d6f-4103a2996b28",
   "metadata": {},
   "source": [
    "### char.istitle(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "1b1e0bcd-6143-47da-9a4b-92573a4b3516",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(False)"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.istitle(\"ABC\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d71a2989-089b-44bb-92cb-b3f6b4ac8333",
   "metadata": {},
   "source": [
    "### char.isupper(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "4da80a6b-9ea5-46a0-b728-ac6add61b130",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str = \"GHC\"\n",
    "np.char.isupper(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "4845253c-7a94-45f5-8282-6325cb6e6e3e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False,  True, False])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([\"hello\", \"HELLO\", \"Hello\"])\n",
    "np.char.isupper(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5adc6f3-1dbb-42aa-9e36-db23ea85d4d9",
   "metadata": {},
   "source": [
    "### char.rfind(a, sub, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "6364c512-cf19-4b94-8cc8-c0fe9d55cb6a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(3)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rfind(\"abcbd\",\"b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28e847a5-860e-401b-8f9a-6e60eab378f5",
   "metadata": {},
   "source": [
    "### char.rindex(a, sub, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "e2be26e6-81c7-4e9e-838c-23ed386958cd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(2)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.rindex(\"abac\",\"a\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b26a200-541b-41d1-902a-1a5530fcc7fe",
   "metadata": {},
   "source": [
    "### char.startswith(a, prefix, start=0, end=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "41f56baf-aaf6-4319-999c-f14f8bae85ab",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(True)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.startswith(\"abcad\",\"abc\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b80bd36-f78e-483a-ad5e-28a26ad9bd25",
   "metadata": {},
   "source": [
    "### char.str_len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "5e61fd97-d0c4-4dd1-aedf-5c7492624d67",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([23, 15])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array(['Grace Hopper Conference', 'Open Source Day'])\n",
    "np.char.str_len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "2d3e8514-1432-4316-96e5-7ad849cca8c7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([u'Р', u'о'])\n",
    "np.char.str_len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "ca27ca9f-1b4c-4ac4-8ee1-d57967da041b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 5],\n",
       "       [1, 1]])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([['hello', 'world'], [u'Р', u'о']])\n",
    "np.char.str_len(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42db0ea7-80ee-4b1f-b4a3-2de585304bd0",
   "metadata": {
    "tags": [],
    "toc-hr-collapsed": true
   },
   "source": [
    "## 便利构造函数\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "array(obj[, itemsize, copy, unicode, order])|创建一个 chararray。\n",
    "asarray(obj[, itemsize, unicode, order])|将输入转换为 chararray ，仅在必要时复制数据。\n",
    "chararray(shape[, itemsize, unicode, …])|提供有关字符串和Unicode值数组的便捷视图。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "011cec63-e9da-4b6f-a4e7-ea2fb84a77ce",
   "metadata": {},
   "source": [
    "### char.array(obj, itemsize=None, copy=True, unicode=None, order=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "a17b1f61-e66e-4d85-a56f-98cec1b27100",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "chararray(['a', 'b', 'c'], dtype='<U1')"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.array([\"a\",\"b\",\"c\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e48e6ba-4e20-44f6-8dd5-297b7e376d28",
   "metadata": {},
   "source": [
    "### char.asarray(obj, itemsize=None, unicode=None, order=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "0b68c462-8b88-45b0-8945-f690acee1443",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "chararray(['a', 'b', 'c'], dtype='<U1')"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.char.asarray([\"a\",\"b\",\"c\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82f9a7c4-7306-4f73-aa55-57a0ae34ba9d",
   "metadata": {
    "tags": [],
    "toc-hr-collapsed": true
   },
   "source": [
    "## 时间日期相关\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "datetime_as_string(arr[, unit, timezone, …])|将日期时间数组转换为字符串数组。\n",
    "datetime_data(dtype, /)|获取有关日期或时间类型的步长的信息。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51f84344-6780-4fea-95bb-5e1bceff12e1",
   "metadata": {
    "tags": []
   },
   "source": [
    "### numpy.datetime_as_string(arr, unit=None, timezone='naive', casting='same_kind')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "72a54516-10e4-437d-8e82-77e5a750b074",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2002-10-27T04:30', '2002-10-27T05:30', '2002-10-27T06:30',\n",
       "       '2002-10-27T07:30'], dtype='datetime64[m]')"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = np.arange('2002-10-27T04:30', 4*60, 60, dtype='M8[m]')\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "9079972a-1ca3-4aef-9b0b-df4e9ed1aea0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2002-10-27T04:30Z', '2002-10-27T05:30Z', '2002-10-27T06:30Z',\n",
       "       '2002-10-27T07:30Z'], dtype='<U35')"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.datetime_as_string(d, timezone='UTC')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "74909dc2-fd10-43d1-ade3-ed32475183c3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2002-10-27T00:30-0400', '2002-10-27T01:30-0400',\n",
       "       '2002-10-27T01:30-0500', '2002-10-27T02:30-0500'], dtype='<U39')"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.datetime_as_string(d, timezone=pytz.timezone('US/Eastern'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "bec7aa1b-b178-46ff-8cac-c02d0b2f932a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2002-10-27T04', '2002-10-27T05', '2002-10-27T06', '2002-10-27T07'],\n",
       "      dtype='<U32')"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.datetime_as_string(d, unit='h')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "1236ef15-22b8-4753-a87d-aee6c7f398ff",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2002-10-27T04:30:00', '2002-10-27T05:30:00',\n",
       "       '2002-10-27T06:30:00', '2002-10-27T07:30:00'], dtype='<U38')"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.datetime_as_string(d, unit='s')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90576c68-a250-41aa-9a1f-04a39e431b52",
   "metadata": {},
   "source": [
    "### numpy.datetime_data(dtype, /)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "c12306c0-6d14-404d-b52d-a840b8ef53d4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('s', 25)"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt_25s = np.dtype('timedelta64[25s]')\n",
    "np.datetime_data(dt_25s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "c72bd9ca-8bbf-4b0e-8135-4190c42ab9e3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(250, dtype='timedelta64[s]')"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(10, dt_25s).astype('timedelta64[s]')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "7ac1dbe2-0b18-4727-9d22-ceac275a02e2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2010-01-01T00:00:00','25s')"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.datetime64('2010', np.datetime_data(dt_25s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4060b939-d95e-42d8-8216-106405fde8c9",
   "metadata": {
    "tags": [],
    "toc-hr-collapsed": true
   },
   "source": [
    "## 工作日函数\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "busdaycalendar([weekmask, holidays])|一个工作日日历对象，它有效地存储定义Busday系列函数的有效天数的信息。\n",
    "is_busday(dates[, weekmask, holidays, …])|计算给定日期中哪些是有效日期，哪些不是。\n",
    "busday_offset(dates, offsets[, roll, …])|首先根据滚动规则将日期调整为属于有效日期，然后将偏移量应用于有效日期中计算的给定日期。\n",
    "busday_count(begindates, enddates[, …])|计算介于beginupdates和结束日期之间的有效天数，不包括结束日期。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5e76917-5a17-4a70-bdaf-3ee932dc9449",
   "metadata": {},
   "source": [
    "### class numpy.busdaycalendar(weekmask='1111100', holidays=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "48e4fc9d-130d-4b91-9f44-d8a975386377",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "bdd = np.busdaycalendar(\n",
    "            holidays=['2011-07-01', '2011-07-04', '2011-07-17'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "70e8f480-cf7a-41bf-8b42-f678c72cc4df",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True,  True, False, False])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdd.weekmask"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "7d6cb166-bd13-441b-bae8-d585a9676e18",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2011-07-01', '2011-07-04'], dtype='datetime64[D]')"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdd.holidays"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cb1e57c-352a-463e-8c03-137045793b83",
   "metadata": {},
   "source": [
    "### numpy.is_busday(dates, weekmask='1111100', holidays=None, busdaycal=None, out=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "2c158f4c-5fa3-45f2-8b9f-aebef1d942c0",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False,  True])"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.is_busday(['2011-07-01', '2011-07-02', '2011-07-18'],\n",
    "    holidays=['2011-07-01', '2011-07-04', '2011-07-17'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff53ea28-b743-453d-b616-d460694c0149",
   "metadata": {},
   "source": [
    "### numpy.busday_offset(dates, offsets, roll='raise', weekmask='1111100', holidays=None, busdaycal=None, out=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "3c632995-c0c3-4c51-8961-905b6c2d82bd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2011-10-03')"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2011-10', 0, roll='forward')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "65646c85-9b2f-42f7-a38b-446b1808812f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2012-02-29')"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2012-03', -1, roll='forward')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "7eea7b09-edcb-4caf-a4f5-23c5b4f42c91",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2011-01-19')"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2011-01', 2, roll='forward', weekmask='Wed')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "9fe68bac-b135-4157-a74b-6a331c7ddb4b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2012-05-13')"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2012-05', 1, roll='forward', weekmask='Sun')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "280033b0-023d-49ac-b9c9-d06c40d293fc",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2011-03-21')"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2011-03-20', 0, roll='forward')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3c7f68e-f9d1-4e9b-b002-feed00f765ae",
   "metadata": {
    "tags": []
   },
   "source": [
    "np.busday_offset('2011-03-22', 0, roll='forward')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "0c750230-5dda-4564-8a41-287037ac0ba2",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2011-03-21')"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2011-03-20', 1, roll='backward')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "d768d0d1-b9b8-43ce-9ef7-58f87324d94f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.datetime64('2011-03-23')"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_offset('2011-03-22', 1, roll='backward')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee3923cf-d2dc-41f7-98e4-7fcebe7fa8dd",
   "metadata": {},
   "source": [
    "### numpy.busday_count(begindates, enddates, weekmask='1111100', holidays=[], busdaycal=None, out=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "4ddfeeae-2016-4435-942c-bc253f7b336e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_count('2011-01', '2011-02')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "c972a33f-fdd6-486a-b9ed-b8be3602415d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "260"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_count('2011', '2012')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "e9f635d8-97ba-4e90-9891-36332edb360c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "53"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.busday_count('2011', '2012', weekmask='Sat')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
